package com.starblink.basic.log

import android.content.Context
import com.tencent.mars.xlog.Log
import com.tencent.mars.xlog.Xlog

object MarsXLogMgr {

    @Throws(IllegalStateException::class)
    @JvmStatic
    fun initXLog(context: Context) {
        try {
            val logPath = "${context.externalCacheDir?.parent}/xlog"
            val cachePath = "${context.externalCacheDir?.parent}/xlog_cache"
            System.loadLibrary("c++_shared")
            System.loadLibrary("marsxlog")

            val xlog = Xlog()
            Log.setLogImp(xlog)
            Log.setLevel(Xlog.LEVEL_VERBOSE, true)
            Log.setConsoleLogOpen(BuildConfig.DEBUG)
            Log.getImpl()
                .appenderOpen(
                    Xlog.LEVEL_VERBOSE,
                    Xlog.AppednerModeAsync,
                    cachePath,
                    logPath,
                    "",
                    0
                )
        } catch (e: Throwable) {
            throw IllegalStateException(e)
        }
    }
}